package String_demo;

import java.util.Scanner;

public class StringDemo03 {
    public static void main(String[] args) {
        /**
         * 应用案例:
         * 从一个邮箱地址中截取 用户名
         */
        //                用户名    @服务器
        //              01234567890123456789012
//        String email = "xiewangzhenyanshizuiqiangde@foxmail.com";
//        int index = email.indexOf('@');
////        //String name = email.substring(0,11);
//        String name = email.substring(0,index);
//        System.out.println(name);

        /**
         *
         *
         */

        Scanner scan = new Scanner(System.in);
        String email;
        do{
            System.out.println("请输入邮箱地址:");
            email = scan.nextLine();
        }while (email == null || email.trim().equals("")
                || email.indexOf("@")==-1
        );
        int index = email.indexOf("@");
        String name = email.substring(0,index);
        String host = email.substring(index);
        System.out.println(name);
        System.out.println(host);




    }
}
